import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class TravelItem {
  TravelItem.fromJson(v);

  toJson() {}
}

/// 含有命令构造函数的模型
class TravelItemModel {
  // int totalCount;
  // List<TravelItem> resultList;

  late int totalCount;
  List<TravelItem>? resultList;

  TravelItemModel.fromJson(Map<String, dynamic> json) {
    totalCount = json['totalCount'];
    if (json['resultList'] != null) {
      resultList = <TravelItem>[];
      json['resultList'].forEach((v) {
        resultList?.add(TravelItem.fromJson(v));
      });
    }
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = Map<String, dynamic>();
    data['totalCount'] = this.totalCount;
    if (this.resultList != null) {
      //有空指针风险
      // data['resultList'] = this.resultList.map((v) => v.toJson()).toList();
      data['resultList'] = this.resultList?.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

/// 含有命名工厂构造函数的模型
/// 含有命名工厂构造函数的模型通常需要有自己的构造函数，构造函数通常采用可选参数，
/// 所以在进行适配时首先要明确哪些字段一定不为空，哪些字段可空，确认好之后就可以进行下面适配了：
class CommonModel {
  // final String icon;
  // final String title;
  // final String url;
  // final String statusBarColor;
  // final bool hideAppBar;
  // CommonModel(
  //     {this.icon, this.title, this.url, this.statusBarColor, this.hideAppBar});
  // 对于可空的字段通过?进行修饰

  final String? icon;
  final String? title;
  final String url;
  final String? statusBarColor;
  final bool? hideAppBar;

  CommonModel(
      {this.icon,
      this.title,
      required this.url,
      this.statusBarColor,
      this.hideAppBar});

  factory CommonModel.fromJson(Map<String, dynamic> json) {
    return CommonModel(
        icon: json['icon'],
        title: json['title'],
        url: json['url'],
        statusBarColor: json['statusBarColor'],
        hideAppBar: json['hideAppBar']);
  }
}
